import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { defHttp } from '/@/utils/http/axios';
import { render, formattingMin, formattingDay } from '/@/utils/common/renderUtils';
import { UploadTypeEnum } from '/@/components/Form/src/jeecg/components/JUpload';


export const earlyBirdPriceColumns : BasicColumn[] = [
	{
		title: '早鸟价开始时间',
		align: "center",
		dataIndex: 'startdate',
		edit: true,
		editable: false,
		editRow: true,
		editRule: false,
		//editRow: true,
		editComponent: 'DatePicker',
		editComponentProps: {
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			format: 'YYYY-MM-DD HH:mm:ss',
			showTime: true
		},
	},
/* 	{
		title: '早鸟价结束时间',
		align: "center",
		dataIndex: 'enddate',
		edit: true,
		editable: false,
		editRow: true,
		editRule: false,
		//editRow: true,
		editComponent: 'DatePicker',
		editComponentProps: {
			valueFormat: 'YYYY-MM-DD',
			format: 'YYYY-MM-DD',
		},
	}, */
	{
		title: '排序',
		align: "center",
		editRow: true,
		editRule: false,
		editComponent: 'InputNumber',
		dataIndex: 'sortnum'
	},
	{
		title: '早鸟价截止时间',
		align: "center",
		dataIndex: 'priceexpiretime',
		editRow: true,
		editRule: false,
		//editRow: true,
		editComponent: 'DatePicker',
		editComponentProps: {
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			format: 'YYYY-MM-DD HH:mm:ss',
			showTime: true
		},
	},
	{
		title: '早鸟价',
		align: "center",
		editRow: true,
		editRule: false,
		editComponent: 'InputNumber',
		dataIndex: 'activeprice'
	},
];
export const usersColumns : BasicColumn[] = [
	/* {
	  title: '是否删除',
	  align:"center",
	  dataIndex: 'trash'
	 }, */
	{
		title: '编号',
		align: 'center',
		dataIndex: 'id',
	},
	{
		title: '出发日期',
		align: "center",
		dataIndex: 'soDay',
		editRow: true,
		editRule: false,
		//editRow: true,
		editComponent: 'DatePicker',
		editComponentProps: {
			valueFormat: 'YYYY-MM-DD',
			format: 'YYYY-MM-DD',
		},
	},
	/* 	{
			title: '结束日期',
			align: "center",
			dataIndex: 'toDay',
			editRow: true,
			editRule: false,
			//editRow: true,
			editComponent: 'DatePicker',
			editComponentProps: {
				valueFormat: 'YYYY-MM-DD',
				format: 'YYYY-MM-DD',
			},
		}, */
	{
		title: '价格',
		align: "center",
		editRow: true,
		editRule: false,
		//editRow: true,
		editComponent: 'InputNumber',
		dataIndex: 'price',

	},
]
export const alternativeColumns : BasicColumn[] = [
	/* {
	  title: '是否删除',
	  align:"center",
	  dataIndex: 'trash'
	 }, */
	{
		title: '编号',
		align: 'center',
		dataIndex: 'id',
	},
	{
		title: '开始日期',
		align: "center",
		dataIndex: 'soDay',
		editRow: true,
		editRule: false,
		//editRow: true,
		editComponent: 'DatePicker',
		editComponentProps: {
			valueFormat: 'YYYY-MM-DD',
			format: 'YYYY-MM-DD',
		},
	},
	{
		title: '结束日期',
		align: "center",
		dataIndex: 'toDay',
		editRow: true,
		editRule: false,
		//editRow: true,
		editComponent: 'DatePicker',
		editComponentProps: {
			valueFormat: 'YYYY-MM-DD',
			format: 'YYYY-MM-DD',
		},
	},
	{
		title: '价格',
		align: "center",
		editRow: true,
		editRule: false,
		//editRow: true,
		editComponent: 'InputNumber',
		dataIndex: 'price',

	},
]

export const tieredPricingColumns : BasicColumn[] = [
	/* {
	  title: '是否删除',
	  align:"center",
	  dataIndex: 'trash'
	 }, */
	{
		title: '编号',
		align: 'center',
		dataIndex: 'id',
	},
	{
		title: '从多少人',
		align: "center",
		editRow: true,
		editRule: false,
		dataIndex: 'minNum',

	},
	{
		title: '到多少人',
		align: "center",
		editRow: true,
		editRule: false,
		dataIndex: 'maxNum',
	},
	{
		title: '成团价格',
		align: "center",
		editRow: true,
		editRule: false,
		dataIndex: 'price',
	},
	/* 	{
			title: '操作',
			dataIndex: 'operation',
			align: 'center',
			width: 200,
			slots: { customRender: 'action' },
		}, */

]

export const payPriceColumns : BasicColumn[] = [
	/* {
	  title: '是否删除',
	  align:"center",
	  dataIndex: 'trash'
	 }, */
	{
		title: '编号',
		align: 'center',
		dataIndex: 'id',
	},
	{
		title: '从多少人',
		align: "center",
		editRow: true,
		editRule: false,
		dataIndex: 'minNum',

	},
	{
		title: '到多少人',
		align: "center",
		editRow: true,
		editRule: false,
		dataIndex: 'maxNum',
	},
	{
		title: '优惠价格/人',
		align: "center",
		editRow: true,
		editRule: false,
		dataIndex: 'price',
	},
	/* 	{
		   title: '操作',
		   dataIndex: 'operation',
		   align: 'center',
		   width: 200,
		   slots: { customRender: 'action' },
	   }, */
]
//列表数据
export const columns : BasicColumn[] = [
	/* {
	  title: '是否删除',
	  align:"center",
	  dataIndex: 'trash'
	 }, */
	{
		title: '创建时间',
		align: "center",
		dataIndex: 'createtime',
		customRender: ({ text }) => {
			return formattingMin(text);
		}
	},
	{
		title: '状态。',
		align: "center",
		dataIndex: 'stats_dictText'
	},


	{
		title: '开始日期',
		align: "center",
		dataIndex: 'startdate',
		customRender: ({ text }) => {
			return formattingDay(text);
		}
	},
	{
		title: '结束日期',
		align: "center",
		dataIndex: 'enddate',
		customRender: ({ text }) => {
			return formattingDay(text);
		}
	},
	{
		title: '起步价',
		align: "center",
		dataIndex: 'mainstartprice'
	},
	{
		title: '出发城市',
		align: "center",
		dataIndex: 'startpoint',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return o.mainCity
		}
	},
	/* {
		title: '上车点',
		align: "center",
		dataIndex: 'pickUpIds_dictText'
	}, */
	{
		title: '主标题',
		align: "center",
		dataIndex: 'titlegroup',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return o.mainTitle
		},
		ellipsis: true
	},
	{
		title: '副标题',
		align: "center",
		dataIndex: 'titlegroup',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return o.secondTitle
		},
		ellipsis: true

	}, {
		title: '首页类别',
		align: "center",
		dataIndex: 'extinfor',
		customRender: ({ text }) => {
			let o = JSON.parse(text)
			return o.typeHomePage || '不显示'
		},
		ellipsis: true

	},
	{
		title: '图片',
		align: "center",
		dataIndex: 'images',
		//customRender: render.renderImage,
		customRender: ({ text }) => {
			if (text.indexOf('https') == -1) {
				return text;
			}
			let imgs = JSON.parse(text)

			return render.renderImage({ text: imgs.join(',') })
		},
	},
	/* 	{
			title: '出发行程日历',
			align: "center",
			dataIndex: 'travelcalendar'
		}, */
	/* 	{
			title: '旅游主路线',
			align: "center",
			dataIndex: 'maintourtravellinerecordlist'
		}, */
	/* 	{
			title: '内容页，map对象',
			align: "center",
			dataIndex: 'content'
		}, */
	/* 	{
			title: '阶梯价格',
			align: "center",
			dataIndex: 'stepprice'
		}, */
	/* 	{
			title: '其他信息',
			align: "center",
			dataIndex: 'extinfor'
		}, */
];
//查询数据
export const searchFormSchema : FormSchema[] = [
];
//表单数据
export const formSchema : FormSchema[] = [
	/*  {
		label: '是否删除',
		field: 'trash',
		component: 'Input',
		dynamicRules: ({model,schema}) => {
			  return [
					 { required: true, message: '请输入是否删除!'},
			  ];
		 },
	  }, */
	/* 	{
			label: '状态。',
			field: 'stats',
			component: 'JDictSelectTag',
			componentProps: {
				dictCode: 'max_stroke_state'
			},
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请选择状态。!' },
				];
			},
		}, */
	//根据日期生成的游玩天数，预设id筛选预设好的路线  出发城市、上车地点，出发城市会有多个，上车地点也是单独选择

	{
		label: '出发城市',
		field: 'cityIds',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: 'sys_category,name,city_id,pid="1760922454642933761"'
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择状态。!' },
			];
		},
		dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		},
	},
	{
		label: '主上车地点',
		field: 'pickUpIds',
		component: 'ApiSelect',
		required: true,
		componentProps: ({ formActionType, formModel }) => {
			if (formModel.cityIds) {
				return {
					//multiple: 多选；不填写为单选
					mode: 'multiple',
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/setting/couplePickUpPoint/list?pageSize=100&cityId=' + formModel.cityIds }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'address',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
					},
					//返回结果字段
					resultField: 'records'
				}
			}

		},
	},
	{
		label: '备选上车地点',
		field: 'alternatePickUpPoint',
		component: 'ApiSelect',
		required: true,
		componentProps: ({ formActionType, formModel }) => {
			if (formModel.cityIds && formModel.pickUpIds) {
				return {
					//multiple: 多选；不填写为单选
					mode: 'multiple',
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/setting/couplePickUpPoint/list?pageSize=100&cityId=' + formModel.cityIds + "&yiPoint=" + formModel.pickUpIds }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'address',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
					},
					//返回结果字段
					resultField: 'records'
				}
			}

		},
	},
	//类别选择
	{
		label: '类别选择',
		field: 'homeType',
		component: 'JSearchSelect',
		componentProps: {
			dict: 'Bs_City_Home_Style,title,id,type="Type"',
			onChange: (e : any, record : any) => {
				console.log(e)
			}
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择类别!' },
			];
		},
		/* dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		}, */
		/* dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		}, */
	},
	
	
	{
		label: '目的地景点',
		field: 'destination',
		component: 'JSearchSelect',
		componentProps: {
			dict: 'BS_Scenic,title,id',
			pageSize: 10,
			async: true,
			onChange: (e : any, record : any) => {
				console.log(e)
			}
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择目的地景点。!' },
			];
		},
		dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		},
		/* dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		}, */
	},
	/* {
		label: '增值服务类别',
		field: 'keyCode',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "pdt_category"
		},
		//required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择绑定产品类别。!' },
			];
		},
	}, */
/* 	{
		label: '增值服务产品',
		field: 'pdtIds',
		component: 'JSelectMultiple',
		componentProps: {
			dictCode: "couple_shop_pdt,title,id"
		},
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择绑定产品!' },
			];
		},
	}, */

	{
		label: '游玩天数',
		field: 'jDays',
		component: 'Input',
		required: true,
		/* componentProps: ({ formActionType, formModel }) => {
			if(formModel.isUpdate==true){
			}
		}, */
		dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		},

	},

	{
		label: '上架',
		field: 'sjSelect',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '立即上架', value: '1' },
				{ label: '定时上架', value: '0' },
			]
		},
	},

	{
		label: '上架时间',
		field: 'startdateStr',
		component: 'DatePicker',
		componentProps: {
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			showTime: true
		},
		show: ({ values }) => {
			return values.sjSelect == 0
		}
	},
	{
		label: '下架',
		field: 'xjSelect',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '手动下架', value: '1' },
				{ label: '定时下架', value: '0' },
			]
		},
	},
	{
		label: '下架时间',
		field: 'enddateStr',
		component: 'DatePicker',
		componentProps: {
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			showTime: true
		},
		show: ({ values }) => {
			return values.xjSelect == 0
		}
	},
	//查找预设路线id
	{
		label: '预设路线',
		field: 'travelLineId',
		component: 'ApiSelect',
		required: true,
		componentProps: ({ formActionType, formModel }) => {

			if (formModel.cityIds && formModel.jDays && formModel.destination) {
				return {
					//multiple: 多选；不填写为单选
					mode: '',
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/journey/bsTravelgroupTravelistgroup/getTravelLinesByCityId?pageSize=100&cityId=' + formModel.cityIds + '&days=' + formModel.jDays + '&destination=' + formModel.destination }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'prelinename',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
						carpoolBus: formModel.carpoolBus
					},
					//返回结果字段
					resultField: 'records',
					onChange: async (e : any, record : any) => {
						console.log('----')
						let o = await defHttp.get({ url: '/journey/bsTravelgroupTravelistgroup/getMsgByPreline?preId=' + e })
						console.log(o.descriptionOfFees)

						formModel.descriptionOfFees = o.descriptionOfFees
						formModel.itineraryHighlights = o.itineraryHighlights

					}
				}
			}

		},
		/* 	colProps:{
				span:12
			}, */
		dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		},
	},
	{
		label: '虚拟报名人数',
		field: 'virtualUserNum',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入虚拟报名人数!' },
			];
		},
		/* colProps:{
			span:12
		}, */
	},
	{
		label: '成团人数',
		field: 'groupUserSize',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入成团人数!' },
			];
		},
		dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		},

	},
	{
		label: '满员人数',
		field: 'maxUserNum',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入最大人数!' },
			];
		},
		/* 	colProps:{
				span:12
			}, */

	},

	{
		label: '起步价',
		field: 'mainstartprice',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入起步价!' },
			];
		},
	},
	{
		label: '划线价',
		field: 'crossedPrice',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入划线价!' },
			];
		},
	},
	{
		label: '是否设置早鸟价',
		field: 'isEarly',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '是', value: 1 },
				{ label: '否', value: 0 }
			]
		}

	},

	{
		label: '早鸟价',
		field: 'earlyBirdPrice',
		component: 'InputNumber',
		slot: 'earlyBirdPrice',
		show: ({ values }) => {
			return values.isEarly == 1
		}
	},
	/* 	{
			label: '创建时间',
			field: 'createtime',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入创建时间!' },
				];
			},
		}, */
	/* 	{
			label: '上车点',
			field: 'startpoint',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入上车点!' },
				];
			},
		}, */
	{
		label: '主标题',
		field: 'mainTitle',
		component: 'InputTextArea',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入主标题!' },
			];
		},
	},
	{
		label: '副标题',
		field: 'secondTitle',
		component: 'InputTextArea',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入副标题!' },
			];
		},
	},
	{
		label: '标签',
		field: 'tagsTitle',
		component: 'InputTextArea',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入标签!' },
			];
		},
	},

	{
		label: '用户可选日期',
		field: 'alternativeTravelcalendar',
		component: 'Input',
		slot: 'selectTravelCalendar',
		/* 	dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请选择出发行程日历!' },
				];
			}, */
	},
	{
		label: '确定出发日期',
		field: 'travelcalendar',
		component: 'Input',
		slot: 'ScheduleSelection',
		/* 	dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请选择出发行程日历!' },
				];
			}, */
	},
	/* 	{
			label: '旅游主路线',
			field: 'maintourtravellinerecordlist',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入旅游主路线!' },
				];
			},
		}, 
		{
			label: '内容页，map对象',
			field: 'content',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入内容页，map对象!' },
				];
			},
		},*/
	{
		label: '成团阶梯价格',
		field: 'stepprice',
		component: 'Input',
		slot: 'TieredPrice',
		/* 	dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入阶梯价格!' },
				];
			}, */
	},
	{
		label: '支付优惠价格',
		field: 'payPrice',
		component: 'Input',
		slot: 'PayPrices',
		/* 	dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入阶梯价格!' },
				];
			}, */

	},
	{
		label: '图片',
		field: 'images',
		component: 'JUpload',
		helpMessage: '最多上传20张图片',
		componentProps: {
			fileType: UploadTypeEnum.image,
			maxCount: 20,
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请上传图片!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	{
		label: '行程亮点',
		field: 'itineraryHighlights',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程简介!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	{
		label: '费用说明',
		field: 'descriptionOfFees',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程简介!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	{
		label: '退改规则说明',
		field: 'retrofitRule',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程简介!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	{
		label: '行前必看',
		field: 'mustSee',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程简介!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	{
		label: '行程详情',
		field: 'msg',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程简介!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	/* 	{
			label: '其他信息',
			field: 'extinfor',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入其他信息!' },
				];
			},
		}, */
	// TODO 主键隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
	{
		label: '',
		field: 'isUpdate',
		component: 'Input',
		show: false
	},
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData) : FormSchema[] {
	// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
	return formSchema;
}